/*
               File: PrcSetMaskCPF
        Description: Prc Set Mask CPF
             Author: GeneXus C# Generator version 10_2_5-78484
       Generated on: 6/6/2014 9:52:41.48
       Program type: Callable routine
          Main DBMS: sqlserver
*/
using System;
using System.Collections;
using GeneXus.Utils;
using GeneXus.Resources;
using GeneXus.Application;
using GeneXus.Metadata;
using GeneXus.Data;
using com.genexus;
using GeneXus.Data.ADO;
using GeneXus.Data.NTier;
using GeneXus.Data.NTier.ADO;
using System.Runtime.Remoting;
using GeneXus.WebControls;
using GeneXus.Http;
using GeneXus.Procedure;
using GeneXus.XML;
using GeneXus.Search;
using GeneXus.Encryption;
using GeneXus.Http.Client;
using System.Threading;
using System.Xml.Serialization;
using System.Data.SqlTypes;
using System.ServiceModel;
using System.Runtime.Serialization;
namespace GeneXus.Programs {
   public class prcsetmaskcpf : GXProcedure
   {
      public prcsetmaskcpf( )
      {
         context = new GxContext(  );
         DataStoreUtil.LoadDataStores( context);
         IsMain = true;
         context.SetDefaultTheme("GeneXusXEv2");
      }

      public prcsetmaskcpf( IGxContext context )
      {
         this.context = context;
         IsMain = false;
      }

      public void release( )
      {
      }

      public void execute( String aP0_OldCPF ,
                           out String aP1_NewCPF )
      {
         this.AV9OldCPF = aP0_OldCPF;
         this.AV8NewCPF = "" ;
         initialize();
         executePrivate();
         aP1_NewCPF=this.AV8NewCPF;
      }

      public String executeUdp( String aP0_OldCPF )
      {
         this.AV9OldCPF = aP0_OldCPF;
         this.AV8NewCPF = "" ;
         initialize();
         executePrivate();
         aP1_NewCPF=this.AV8NewCPF;
         return AV8NewCPF ;
      }

      public void executeSubmit( String aP0_OldCPF ,
                                 out String aP1_NewCPF )
      {
         prcsetmaskcpf objprcsetmaskcpf;
         objprcsetmaskcpf = new prcsetmaskcpf();
         objprcsetmaskcpf.AV9OldCPF = aP0_OldCPF;
         objprcsetmaskcpf.AV8NewCPF = "" ;
         objprcsetmaskcpf.context.SetSubmitInitialConfig(context);
         objprcsetmaskcpf.initialize();
         ThreadPool.QueueUserWorkItem( new WaitCallback( executePrivateCatch ),objprcsetmaskcpf);
         aP1_NewCPF=this.AV8NewCPF;
      }

      void executePrivateCatch( object stateInfo )
      {
         try
         {
            ((prcsetmaskcpf)stateInfo).executePrivate();
         }
         catch ( Exception e )
         {
            GXUtil.SaveToEventLog( "Design", e);
            throw e ;
         }
      }

      void executePrivate( )
      {
         /* GeneXus formulas */
         /* Output device settings */
         AV10x = 1;
         while ( AV10x <= StringUtil.Len( AV9OldCPF) )
         {
            AV8NewCPF = AV8NewCPF + StringUtil.Substring( AV9OldCPF, AV10x, 1);
            if ( ( AV10x == 3 ) || ( AV10x == 6 ) )
            {
               AV8NewCPF = AV8NewCPF + ".";
            }
            else if ( AV10x == 9 )
            {
               AV8NewCPF = AV8NewCPF + "-";
            }
            AV10x = (short)(AV10x+1);
         }
         this.cleanup();
      }

      public void cleanup( )
      {
         CloseOpenCursors();
         if ( IsMain )
         {
            context.CloseConnections() ;
         }
         exitApplication();
      }

      protected void CloseOpenCursors( )
      {
      }

      public override void initialize( )
      {
         /* GeneXus formulas. */
         context.Gx_err = 0;
      }

      private short AV10x ;
      private String AV9OldCPF ;
      private String AV8NewCPF ;
      private String aP1_NewCPF ;
   }

}
